package com.ruoyi.yzd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yzd.domain.YzdUnit;
import com.ruoyi.yzd.service.IYzdUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 易制毒-单位Controller
 * 
 * @author zyb
 * @date 2023-07-04
 */
@RestController
@RequestMapping("/access/unit")
public class YzdUnitController extends BaseController
{
    @Autowired
    private IYzdUnitService yzdUnitService;

    /**
     * 查询易制毒-单位列表
     */
    @PreAuthorize("@ss.hasPermi('access:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(YzdUnit yzdUnit)
    {
        startPage();
        List<YzdUnit> list = yzdUnitService.selectYzdUnitList(yzdUnit);
        return getDataTable(list);
    }

    /**
     * 导出易制毒-单位列表
     */
    @PreAuthorize("@ss.hasPermi('access:unit:export')")
    @Log(title = "易制毒-单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YzdUnit yzdUnit)
    {
        List<YzdUnit> list = yzdUnitService.selectYzdUnitList(yzdUnit);
        ExcelUtil<YzdUnit> util = new ExcelUtil<YzdUnit>(YzdUnit.class);
        util.exportExcel(response, list, "易制毒-单位数据");
    }

    /**
     * 获取易制毒-单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('access:unit:query')")
    @GetMapping(value = "/{unitId}")
    public AjaxResult getInfo(@PathVariable("unitId") Long unitId)
    {
        return success(yzdUnitService.selectYzdUnitByUnitId(unitId));
    }

    /**
     * 新增易制毒-单位
     */
    @PreAuthorize("@ss.hasPermi('access:unit:add')")
    @Log(title = "易制毒-单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YzdUnit yzdUnit)
    {
        return toAjax(yzdUnitService.insertYzdUnit(yzdUnit));
    }

    /**
     * 修改易制毒-单位
     */
    @PreAuthorize("@ss.hasPermi('access:unit:edit')")
    @Log(title = "易制毒-单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YzdUnit yzdUnit)
    {
        return toAjax(yzdUnitService.updateYzdUnit(yzdUnit));
    }

    /**
     * 删除易制毒-单位
     */
    @PreAuthorize("@ss.hasPermi('access:unit:remove')")
    @Log(title = "易制毒-单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{unitIds}")
    public AjaxResult remove(@PathVariable Long[] unitIds)
    {
        return toAjax(yzdUnitService.deleteYzdUnitByUnitIds(unitIds));
    }
}
